var _currentPage = 1;
var _pages = 0;
var _contextId = '';
var _courseId = 0;
//上一页
$("#prevPage").click(function () {
    if(_currentPage > 1){
        _currentPage = _currentPage -1;
        findCourseBuyUserList(_currentPage,_contextId,_courseId);
    }
});
//下一页
$("#nextPage").click(function () {
    if(_pages > _currentPage){
        _currentPage = _currentPage + 1;
        findCourseBuyUserList(_currentPage,_contextId,_courseId);
    }
});

/**
 * 获取购买课程的用户数据列表
 * @param pageNo 页码
 * @param contextId 显示内容的ID
 * @param courseId 课程ID
 */
function findCourseBuyUserList(pageNo,contextId,courseId) {
    _contextId = contextId;
    _courseId = courseId;
    $.ajax({
        url: baseloaction +'/web/course/findCourseBuyUserList',
        beforeSend:function(XHR){
            $("#"+contextId).html('<div class="mt20 pt10 mr20 ml10"><div class="text-center pt10 pb10"><span class="loading"></span></div></div>');
        },
        type:'post',
        dataType:'json',
        data:{
            'courseId':courseId,
            'currentPage':pageNo
        },
        success:function (result) {
            if(result.success==true){
                var data = result.entity;
                _pages = data.pages;
                _currentPage = data.pageNum;
                var list = data.list;
                if(list !=null && list.length > 0){
                    var context = '<ol class="clearfix">';
                    $.each(list,function (index,orderDetails) {
                        var user = orderDetails.user;
                        if(user != null && user !='undefined'){
                            context +='<li>';
                            context +='<p>';
                            context +='<a href="javascript:void(0);">';
                            context +='<img data-original="'+user.avatar+'" width="50" height="50" style="display: inline" class="img-circle vam lazy"/>';
                            context +='<span class="c-999 fs12 vam show txtOf mt5">'+user.nickname+'</span>';
                            context +='</a>';
                            context +='</p>';
                            context +='</li>';
                        }
                    });
                    context +='</ol>';
                    $("#"+contextId).html(context);
                    lazyTeacherImage();
                }else if(_currentPage==1){
                    errorText(contextId);
                }
            }else{
                errorText(contextId);
            }
        },
        error:function (error) {
            errorText(contextId);
        }
    });
}

function errorText(contextId) {
    $("#"+contextId).html('<span class="no-data__wrap"><span class="no-data-ico"></span><p class="mt20"><span class="c-666">还没有报名参加的学员~~~</span></p></span>');
}